package com.laoniu.service.sys;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laoniu.mapper.SysUserRoleMapper;
import com.laoniu.entity.SysUserRole;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserRoleService extends ServiceImpl<SysUserRoleMapper, SysUserRole> {

    @Resource
    private SysUserRoleMapper userRoleMapper;

    /**
     * 根据userId获取绑定的角色
     * @param userId
     * @return
     */
    public List<SysUserRole> getUserRoleByUserId(Long userId){
        LambdaQueryWrapper<SysUserRole> wrapper = Wrappers.lambdaQuery(SysUserRole.class);
        wrapper.eq(SysUserRole::getUserId, userId);
        return userRoleMapper.selectList(wrapper);
    }

    public void deleteByUserId(Long userId){
        LambdaQueryWrapper<SysUserRole> wrapper = Wrappers.lambdaQuery(SysUserRole.class);
        wrapper.eq(SysUserRole::getUserId, userId);
        userRoleMapper.delete(wrapper);
    }
}
